using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class LoadingPage : MonoBehaviour
{
    [SerializeField]
    private Image Fill;
    [SerializeField]
    private Text text;
    private AsyncOperation asyncOperation;

    void Start()
    {
        text.text = 0 + "%";
        Fill.fillAmount = 0f;
        StartCoroutine(LoadSceneAsync());
    }

    IEnumerator LoadSceneAsync()
    {
        asyncOperation = SceneManager.LoadSceneAsync(2);
        asyncOperation.allowSceneActivation = false;
        float fakeProgress = 0f;
        while (fakeProgress < 1f)
        {
            fakeProgress += Time.deltaTime * 0.5f; // 模拟加载
            Fill.fillAmount = fakeProgress;
            text.text = Mathf.Floor(fakeProgress * 100) + "%";
            yield return null;
        }
        Fill.fillAmount = 1f;
        text.text = 100 + "%";
        asyncOperation.allowSceneActivation = true;
    }
}
